#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int main()
{
    int i = 0;
    pid_t pid, pid3;
    
    for(i = 0; i < 5; i++) {
        pid = fork();
        if(pid == 0) {
            break;
        }
        if(i == 2) {
            pid3 = pid;
        }
    }
    
    if(i < 5) {
        while(1) {
            printf("\n子进程, pid = %d, ppid = %d\n", getpid(), getppid());
            sleep(3);
        }
    } else if(i == 5) {
        printf("\n\n\n父进程, pid = %d, 将要杀死 3 号子进程, pid3 = %d\n", getpid(), pid3);
        sleep(5);
        kill(pid3, SIGKILL);

        while(1) {
            sleep(1);
        }
    }


    return 0;
}

